﻿(function ($) {

    var addlist = function (target, settings) {


        if (settings.isitemorline == "line") {


            if (settings.state == "read") {
                var $rightlist = $("#divAttributeItems");
                $rightlist[0].innerHTML = "";
                IntialLines($rightlist);
                var $dialog = $("#dialog_activity2");
                var $task1 = $dialog.find("#task1");
                var $task2 = $dialog.find("#task2");
                var $task3 = $dialog.find("#task3");
                var $this = target;
                var mode = $this.attr('conditionUpdateMode');
                if (mode) {
                    $this.attr("conditionUpdateMode", "editing");

                    $task1.val($this.attr("task1"));
                    $task2.val($this.attr("task2"));
                    $task3.val($this.attr("task3"));

                }
                else {
                    $this.attr("conditionUpdateMode", "create");
                    $task1.val($this.attr(""));
                    $task2.val($this.attr(""));
                    $task3.val($this.attr(""));

                }
            }
            if (settings.state == "update") {
                var itemTarget = target
                var $dialog = $("#dialog_activity2");

                var task1 = $dialog.find("#task1").val();
                itemTarget.attr("task1", task1);
                var task2 = $dialog.find("#task2").val();
                itemTarget.attr("task2", task2);
                var task3 = $dialog.find("#task3").val();
                itemTarget.attr("task3", task3);


                itemTarget.attr('conditionUpdateMode', "updated");

            }

        }
        if (settings.isitemorline == "item") {
            if (settings.state == "read") {
                var $rightlist = $("#divAttributeItems");
                $rightlist[0].innerHTML = "";

                IntialItems($rightlist);






                var $dialog = $("#dialog_activity1");
                var $actnum = $dialog.find("#txtNum");
                var $actname = $dialog.find("#txtActName");
                var $actDuration = $dialog.find("#txtActDuration");
                var $actApprover = $dialog.find("#txtActApprover");
                var $approveType = $dialog.find("#ddlApproveType");
                var $rdSerialTrue = $dialog.find("#rdSerialTrue");
                var $rdSerialFalse = $dialog.find("#rdSerialFalse");
                var $pre = $dialog.find("#txtPre");
                var $ActSet = $dialog.find("#txtActSet");
                var $target = target;
                var mode = $target.attr('activityUpdateMode');
                if (mode) {
                    $target.attr("activityUpdateMode", "editing");
                    $actnum.val($target.attr("actnum"));
                    $actname.val($target.attr("actname"));
                    $actDuration.val($target.attr("actDuration"));
                    $actApprover.val($target.attr("actApprover"));
                    $approveType.val($target.attr("approveType"));
                    if ($target.attr("actSerial")) {
                        $rdSerialTrue.attr("checked", "checked");
                    }
                    else {
                        $rdSerialFalse.attr("checked", "checked");
                    }
                    $pre.val($target.attr("pre"));
                    $ActSet.val($target.attr("ActSet"));
                }
                else {
                    $target.attr("activityUpdateMode", "create");
                    $actname.val($target.attr(""));
                    $actDuration.val($target.attr(""));
                    $actApprover.val($target.attr(""));
                    $approveType.val($target.attr(""));
                    $actnum.val($target.attr(""));
                    $pre.val($target.attr(""));
                    $ActSet.val($target.attr(""));
                    
                }
            }
            if (settings.state == "update") {
                var itemTarget = target
                var $dialog = $("#dialog_activity1");

                var pre = $dialog.find("#txtPre").val();
                itemTarget.attr("pre", pre);

                var actnum = $dialog.find("#txtNum").val();
                itemTarget.attr("actnum", actnum);

                var ActSet = $dialog.find("#txtActSet").val();
                itemTarget.attr("ActSet", ActSet);

                var actname = $dialog.find("#txtActName").val();
                itemTarget.attr("actname", actname);

                var actDuration = $dialog.find("#txtActDuration").val();
                itemTarget.attr("actDuration", actDuration);

                var actApprover = $dialog.find("#txtActApprover").val();
                itemTarget.attr("actApprover", actApprover);

                var approveType = $dialog.find("#ddlApproveType").val();
                itemTarget.attr("approveType", approveType);

                var actSerial = $dialog.find("#rdSerialTrue").attr('checked');
                if (actSerial)
                    itemTarget.attr("actSerial", actSerial);

                itemTarget.attr('activityUpdateMode', "updated");



            }


        }
        if (settings.isitemorline == "start") {
            if (settings.state == "read") {
                var $rightlist = $("#divAttributeItems");
                $rightlist[0].innerHTML = "";
                IntialStart($rightlist);
                var $dialog = $("#dialog_activity2");
                var $task1 = $dialog.find("#task1");
                var $task2 = $dialog.find("#task2");
                var $task3 = $dialog.find("#task3");
                var $this = target;
                var mode = $this.attr('conditionUpdateMode');
                if (mode) {
                    $this.attr("conditionUpdateMode", "editing");

                    $task1.val($this.attr("task1"));
                    $task2.val($this.attr("task2"));
                    $task3.val($this.attr("task3"));

                }
                else {
                    $this.attr("conditionUpdateMode", "create");
                    $task1.val($this.attr(""));
                    $task2.val($this.attr(""));
                    $task3.val($this.attr(""));

                }
            }
            if (settings.state == "update") {
                var itemTarget = target
                var $dialog = $("#dialog_activity2");

                var task1 = $dialog.find("#task1").val();
                itemTarget.attr("task1", task1);
                var task2 = $dialog.find("#task2").val();
                itemTarget.attr("task2", task2);
                var task3 = $dialog.find("#task3").val();
                itemTarget.attr("task3", task3);


                itemTarget.attr('conditionUpdateMode', "updated");

            }

        }
        if (settings.isitemorline == "end") {
            if (settings.state == "read") {
                var $rightlist = $("#divAttributeItems");
                $rightlist[0].innerHTML = "";
                IntialEnd($rightlist);
                var $dialog = $("#dialog_activity2");
                var $task1 = $dialog.find("#task1");
                var $task2 = $dialog.find("#task2");
                var $task3 = $dialog.find("#task3");
                var $this = target;
                var mode = $this.attr('conditionUpdateMode');
                if (mode) {
                    $this.attr("conditionUpdateMode", "editing");

                    $task1.val($this.attr("task1"));
                    $task2.val($this.attr("task2"));
                    $task3.val($this.attr("task3"));

                }
                else {
                    $this.attr("conditionUpdateMode", "create");
                    $task1.val($this.attr(""));
                    $task2.val($this.attr(""));
                    $task3.val($this.attr(""));

                }
            }
            if (settings.state == "update") {
                var itemTarget = target
                var $dialog = $("#dialog_activity2");

                var task1 = $dialog.find("#task1").val();
                itemTarget.attr("task1", task1);
                var task2 = $dialog.find("#task2").val();
                itemTarget.attr("task2", task2);
                var task3 = $dialog.find("#task3").val();
                itemTarget.attr("task3", task3);


                itemTarget.attr('conditionUpdateMode', "updated");

            }

        }
    }

    jQuery.fn.addlistfunction = function (options) {
        settings = jQuery.extend({
            isitemorline: null,
            target: null, //当前线||当前项
            state: null
        }, options);
        addlist(this, settings);
        return this;
    };

})(jQuery);


